#!/bin/bash
set -x
set -o errexit
#https://www.elastic.co/guide/en/kibana/6.8/tutorial-load-dataset.html
# https://www.cnblogs.com/shiyu404/p/10571901.html

# wget https://download.elastic.co/demos/kibana/gettingstarted/shakespeare_6.0.json

if [ $# -lt 1 ]; then
 echo "add data... "
 curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary @esdata/shakes_1.json
else
 echo "create index and add data... "
 curl -XPUT "localhost:9200/shakespeare" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "properties": {
            "speaker": {"type": "keyword"},
            "play_name": {"type": "keyword"},
            "line_id": {"type": "integer"},
            "speech_number": {"type": "integer"}
        }
    }
}
'
 curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary @esdata/shakespeare_6.0.json
fi
